<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<center>
		用户名:<input type="text" id="u_name"><br>
		密码  :<input type="password" id="pwd"><br>
		手机号:<input type="text" id="tel"><br>
		验证码:<input type="text" id="code"><button>发送验证码</button>
		<br><input type="button" id="sub" value="注册">
	</center>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
	//发送验证码
	$("button").click(function(){
		var tel = $("#tel").val();
		if (tel == "") {
			alert("请输入手机号");
			return false;
		}
		$.post("sendTemplateSMS.php",{tel:tel},function(res){
            alert(res.msg);
		},'json');
	})
	//注册
	$("#sub").click(function(){
		var tel = $("#tel").val();
		if (tel == "") {
			alert("请输入手机号");
			return false;
		}
		var user = $("#u_name").val();
		if (user == "") {
            alert("用户名不能为空");
            return false;
		}
		var pwd = $("#pwd").val();
		if (pwd.length<8 || pwd.length>16) {
			alert("密码长度必须8-16位");
			return false;
		}
        var code = $("#code").val();
		$.post("register.php",{tel:tel,pwd:pwd,code:code,user:user},function(res){
            alert(res.msg);
            if (res.code==1) {
            	location.href="login.html";
            }
		},'json');
	})
</script>